package com.example.java_websocket.web.controller;

import com.example.java_websocket.model.ChatHistory;
import com.example.java_websocket.model.ChatHistory1;
import com.example.java_websocket.model.User;
import com.example.java_websocket.service.IChatHistoryService;
import com.example.java_websocket.vo.PageVo;
import com.example.java_websocket.vo.RsetResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/History")
// @Api注解的内容写在tags属性里
@Api(tags = "聊天记录接口")
public class ChatHistoryController {

    @Autowired
    private IChatHistoryService chatHistoryService;

    @PostMapping("/add")
    @ApiOperation("添加用户接口")
    public RsetResultVo<ChatHistory1> edit(@Validated @RequestBody ChatHistory1 chatHistory){
        ChatHistory1 add =  chatHistoryService.add(chatHistory);
        return RsetResultVo.success(add);
    }

    @GetMapping("/listHistory")
    @ApiOperation("查询消息历史接口")
    public RsetResultVo<PageVo<ChatHistory1>> listHistory(
            @RequestParam(value = "pageNumber",required = false,defaultValue = "1") Integer pageNumber,
            @RequestParam(value = "pageSize",required = false,defaultValue = "100")Integer pageSize){
        PageVo<ChatHistory1> chatHistoryPageVo = chatHistoryService.listChatHistory(pageNumber, pageSize);
        return  RsetResultVo.success(chatHistoryPageVo);
    }

}
